﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Account_UserMain : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //上传并剪切头像
        //http://www.hdfu.net/thinkphp/avatar/

        hid_uid.Value = Uid.ToString();

    }

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_changPwd_Click(object sender, EventArgs e)
    {
        try
        {
            string oldPwd = txt_pwd.Value.Trim();
            string newpwd=txt_newPwd.Value.Trim();
            string repwd = txt_rePwd.Value.Trim();
            int userid = Uid;

            if (!newpwd.Equals(repwd))//密码确认密码输入错误
            {
                Common.AlertMessageAndRedirect("确认密码和密码不一致，请重新输入！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                return;
            }

            int result = DataHandler.Current.ChangePwd(userid,oldPwd,newpwd);
            switch (result)
            { 
                case 1:
                    Common.AlertMessageAndRedirect("修改密码成功！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                    break;
                case 0:
                    Common.AlertMessageAndRedirect("修改密码失败！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                    break;
                case -1:
                    Common.AlertMessageAndRedirect("用户不存在！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                    break;
                case -2:
                    Common.AlertMessageAndRedirect("原始密码输入错误，请重新输入！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                    break;
                case -3:
                    Common.AlertMessageAndRedirect("系统错误！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
                    break;
                default:
                    break;

            }
        }
        catch {
            Common.AlertMessageAndRedirect("系统错误！", ResolveUrl("~/Account/UserMain.aspx#tab-3"));
        }
    }
}